package qeb.handheldmedical.adapter;

import org.json.JSONArray;
import org.json.JSONObject;

import qeb.handheldmedical.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class OperationListAdapter extends BaseAdapter{

	private static final String TAG = "OtlAdapter";
	
	//private ImageSwitcher mImageLoader;
	private int mCount;
	private Context mContext;
	private JSONArray otlJsonArray =null;
	
	public OperationListAdapter(int count, Context context, JSONArray OperationListJsonArray) {
		this.mCount = count;
		this.mContext = context;
		this.otlJsonArray = OperationListJsonArray;
		//mImageLoader = new ImageSwitcher(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder = null;
		convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_operation, null);
			viewholder = new ViewHolder();
			viewholder.tv_szxm = (TextView)convertView.findViewById(R.id.tv_szxm);
			viewholder.tv_sssj = (TextView)convertView.findViewById(R.id.tv_sssj);
			viewholder.tv_ssmc = (TextView)convertView.findViewById(R.id.tv_ssmc);
			viewholder.tv_clz = (TextView)convertView.findViewById(R.id.tv_clz);
			convertView.setTag(viewholder);
			
			try {
				JSONObject Operation = otlJsonArray.getJSONObject(position);
				if(Operation!=null)
				{
					viewholder.tv_szxm.setText(Operation.getString("XM"));
					viewholder.tv_sssj.setText(Operation.getString("SSSJ"));
					viewholder.tv_ssmc.setText(Operation.getString("SSNAME"));
					viewholder.tv_clz.setText(Operation.getString("ZDYS"));					
				}
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(TAG, e.toString());
			}
		
		return convertView;
	}
	
	static class ViewHolder {
		//ImageView imgPatient;
		TextView tv_szxm;
		TextView tv_sssj;
		TextView tv_ssmc;
		TextView tv_clz;
	}
}